package com.liuzhongni.wahahanews.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.liuzhongni.wahahanews.R;
import com.liuzhongni.wahahanews.adapter.ViewPagerAdapterOfNew;
import com.liuzhongni.wahahanews.fragment.newcolumnfragment.HeadLineFragment;
import com.liuzhongni.wahahanews.fragment.newcolumnfragment.PictureFragment;
import com.liuzhongni.wahahanews.headlineclass.TitleTag;
import com.liuzhongni.wahahanews.headlineclass.Total;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/7.
 */
public class NewsFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ViewPagerAdapterOfNew adapterOfNew;
    private ArrayList<Fragment> data;
    private ArrayList<String> columnData;
    private Total totalData;
    private ArrayList<String> tidList;
    private ArrayList<TitleTag> titleTags;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_news, null);
        tabLayout = (TabLayout) view.findViewById(R.id.tl_new);
        viewPager = (ViewPager) view.findViewById(R.id.vp_new);
        init();
        return view;
    }



    private void init() {

        columnData = new ArrayList<>();
        columnData.add("头条");
        columnData.add("图片");
        data = new ArrayList<>();
        data.add(new HeadLineFragment());
        data.add(new PictureFragment());

        adapterOfNew = new ViewPagerAdapterOfNew(getActivity().getSupportFragmentManager(), data, getActivity(), columnData);
        viewPager.setAdapter(adapterOfNew);
        tabLayout.setupWithViewPager(viewPager);
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(adapterOfNew.getTabView(i));
            }
        }

    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d("NewsFragment", "pause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("NewsFragment", "stop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d("NewsFragment", "destroyview");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("NewsFragment", "destroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d("NewsFragment", "detach");
    }
}
